﻿using LxBasic;
using LxCore;

namespace LxCore
{
    public class ReferenceValue : JsObject
    {
        public FieldBase<Vector3d> Gravity
        {
            get => _Gravity;
            set { _Gravity = value; RaisePropertyChanged(nameof(Gravity)); }
        }
        private FieldBase<Vector3d> _Gravity = new ConstField.Vector(new(0, 0, -9.8));
        public FieldBase<double> ReferenceTemperature
        {
            get => _ReferenceTemperature;
            set { _ReferenceTemperature = value; RaisePropertyChanged(nameof(ReferenceTemperature)); }
        }
        private FieldBase<double> _ReferenceTemperature = new ConstField.Double(300);
        public FieldBase<double> ReferenceDensity
        {
            get => _ReferenceDensity;
            set { _ReferenceDensity = value; RaisePropertyChanged(nameof(ReferenceDensity)); }
        }
        private FieldBase<double> _ReferenceDensity = new ConstField.Double(1);

        public ParameterBase<double> RadiationBackgroundTemperature
        {
            get { return _RadiationBackgroundTemperature; }
            set { _RadiationBackgroundTemperature = value; RaisePropertyChanged(nameof(RadiationBackgroundTemperature)); }
        }
        private ParameterBase<double> _RadiationBackgroundTemperature = new ConstField.Double(300);
        public ParameterBase<double> MinWallDistanceLimit
        {
            get => _MinWallDistanceLimit;
            set { _MinWallDistanceLimit = value; RaisePropertyChanged(nameof(MinWallDistanceLimit)); }
        }
        private ParameterBase<double> _MinWallDistanceLimit = new ConstField.Double(1e-6);
        public override void FromJsonKV(string key, IJsonReader jsReader)
        {
            switch (key)
            {
                case nameof(Gravity): jsReader.ReadObject(Gravity, e => Gravity = e); break;
                case nameof(ReferenceTemperature): jsReader.ReadObject(ReferenceTemperature, e => ReferenceTemperature = e); break;
                default: base.FromJsonKV(key, jsReader); break;
            }
        }
        public override void ToJsonKV(IJsonWriter jsWriter)
        {
            base.ToJsonKV(jsWriter);
            PhysicalModel pm = Parent as PhysicalModel;
            if (pm.BuoyancyType == BuoyancyTypes.Boussinesq模型)
            {
                jsWriter.WriteObject(nameof(Gravity), Gravity, true);
                jsWriter.WriteObject(nameof(ReferenceTemperature), ReferenceTemperature, true);
            }
            else if (pm.BuoyancyType == BuoyancyTypes.参考密度)
            {
                jsWriter.WriteObject(nameof(Gravity), Gravity, true);
                jsWriter.WriteObject(nameof(ReferenceDensity), ReferenceDensity, true);
            }

        }
    }
}
